//
//  CustomScrollView.m
//  UI06_homework1
//
//  Created by aaaaaa on 16/6/13.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CustomScrollView.h"

@implementation CustomScrollView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setProperty];
    }
    return self;
}

- (void)setProperty{
    self.showsHorizontalScrollIndicator = NO;
    self.pagingEnabled = YES;
    self.bounces = NO;
}

- (void)addPicture:(NSArray<UIImage *> *)pictureArray{
    self.contentSize = CGSizeMake(CGRectGetWidth(self.bounds) * (pictureArray.count + 2), CGRectGetHeight(self.bounds));
    self.contentOffset = CGPointMake(CGRectGetWidth(self.bounds), 0);
    for (int i = 0; i < pictureArray.count + 2; i++) {
        UIImageView *imageView = [[UIImageView alloc] init];
        if (i == 0) {
            imageView.image = pictureArray[pictureArray.count - 1];
        } else if (i == pictureArray.count + 1) {
            imageView.image = pictureArray[0];
        } else {
            imageView.image = pictureArray[i - 1];
        }
        imageView.frame = CGRectMake(CGRectGetWidth(self.bounds) * i, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds));
        [self addSubview:imageView];
    }
}





@end
